package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONB;
import com.alibaba.fastjson2.JSONObject;
import com.bw.bean.G1;
import com.bw.bean.G2;
import com.bw.service.gService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class gController {
    @Autowired
    gService service;
    @RequestMapping("g1")
    public JSONObject g1(){
        JSONObject obj = new JSONObject();
        JSONObject o2 = new JSONObject();
        JSONArray arr1 = new JSONArray();
        List<G1> list = service.show1();
        JSONArray arr2 = new JSONArray();
        JSONObject o3 = new JSONObject();
        JSONArray arr3 = new JSONArray();
        for (G1 g : list) {
            arr1.add(g.getName());
            arr3.add(g.getXs());
        }


        o3.put("name","销售额");
        o3.put("data",arr3);
        arr2.add(o3);
        o2.put("categories", arr1);
        o2.put("series", arr2);
        obj.put("status",0);
        obj.put("msg","");
        obj.put("data",o2);
        return obj;
    }
    @RequestMapping("g2")
    public JSONObject g2(){
        JSONObject obj = new JSONObject();
        JSONArray arr1 = new JSONArray();
        List<G2> list = service.show2();
        for (G2 g : list) {
            JSONObject o2 = new JSONObject();
            o2.put("name",g.getName());
            o2.put("value",g.getZb());
            arr1.add(o2);
        }
        obj.put("status",0);
        obj.put("msg","");
        obj.put("data",arr1);
        return obj;
    }
    @RequestMapping("g3")
    public JSONObject g3(){
        JSONObject obj = new JSONObject();
        obj.put("status",0);
        obj.put("msg","");
        obj.put("data",service.show3());
        return obj;
    }
}
